package com.example.parking.interfaces.http;

import com.example.parking.application.EntryExitService;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import com.example.parking.interfaces.http.dto.EntryRequest;
import com.example.parking.interfaces.http.dto.ExitRequest;

import java.math.BigDecimal;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class EntryExitController {
    private final EntryExitService entryExitService;

    public EntryExitController(EntryExitService entryExitService) {
        this.entryExitService = entryExitService;
    }

    @PostMapping("/entry")
    @ResponseStatus(HttpStatus.CREATED)
    public Map<String, Object> entry(@Valid @RequestBody EntryRequest request) {
        Long orderId = entryExitService.vehicleEntry(request.getLotCode(), request.getSpaceCode(), request.getPlateNo());
        return Map.of("orderId", orderId);
    }

    @PostMapping("/exit")
    public Map<String, Object> exit(@Valid @RequestBody ExitRequest request) {
        BigDecimal fee = entryExitService.vehicleExit(request.getLotCode(), request.getSpaceCode(), request.getPlateNo());
        return Map.of("fee", fee);
    }
}


